package com.ld.poetry.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ld.poetry.config.PoetryResult;
import com.ld.poetry.dao.ProhibitedWordsMapper;
import com.ld.poetry.entity.ProhibitedWords;
import com.ld.poetry.entity.User;
import com.ld.poetry.service.ProhibitedWordsService;
import com.ld.poetry.vo.ProhibitedWordsVO;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * @Author: 杨旭
 * @PackageName: poetize
 * @Package: com.ld.poetry.service.impl
 * @Date: 2023/7/4 13:00
 * @explain:
 */
@Service
public class ProhibitedWordsServiceImpl extends ServiceImpl<ProhibitedWordsMapper, ProhibitedWords> implements ProhibitedWordsService {


    @Override
    public PoetryResult<Page> listProWord(ProhibitedWordsVO prohibitedWordsVO) {
        LambdaQueryChainWrapper<ProhibitedWords> lambdaQuery = lambdaQuery();

        if (StringUtils.hasText(prohibitedWordsVO.getSearchKey())) {
            lambdaQuery.like(ProhibitedWords::getWord, prohibitedWordsVO.getSearchKey());
        }

        return PoetryResult.success(lambdaQuery.page(prohibitedWordsVO));
    }

    @Override
    public PoetryResult add(ProhibitedWords prohibitedWords) {
        // 判断是否存在
        ProhibitedWords one = lambdaQuery().eq(ProhibitedWords::getWord, prohibitedWords.getWord()).one();
        if (one != null) {
            return PoetryResult.success("已存在");
        }
        return PoetryResult.success(save(prohibitedWords));
    }
}
